package ctrl;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class ListStyleButtonSet extends VerticalFieldManager
{
	int lastFocusIndex=0;
	
	public ListStyleButtonSet()
    {
        super(VERTICAL_SCROLL);
        setMargin(5, 5, 5, 5);
    }
	
	public void getFocus()
	{
		Field field=getLeafFieldWithFocus();
		
		if(field instanceof ListStyleButtonField)
		{
			lastFocusIndex=field.getIndex();
		}
	}
	
/*	
	public void setFocus()
	{
		if(getFieldCount()>0 && getFieldCount()>=lastFocusIndex)
		{
			getField(lastFocusIndex).setFocus();
		}
		
		//super.setFocus();
	}
*/
	
    protected void sublayout(int maxWidth, int maxHeight)
    {
        super.sublayout(maxWidth, maxHeight);
        
        int numChildren = this.getFieldCount();
        if(numChildren > 0) {
            if(numChildren == 1) {
                Field child = getField(0);
                if(child instanceof ListStyleButtonField) {
                    ((ListStyleButtonField) child).setDrawPosition(ListStyleButtonField.DRAWPOSITION_SINGLE);
                }
            } else {
                int index = 0;
                Field child = getField(index);
                if(child instanceof ListStyleButtonField) {
                    ((ListStyleButtonField) child).setDrawPosition(ListStyleButtonField.DRAWPOSITION_TOP);
                }

                for(index = 1; index < numChildren - 1; index++) {
                    child = getField(index);
                    if(child instanceof ListStyleButtonField) {
                        ((ListStyleButtonField) child).setDrawPosition(ListStyleButtonField.DRAWPOSITION_MIDDLE);
                    }
                }
                child = getField(index);
                if(child instanceof ListStyleButtonField) {
                    ((ListStyleButtonField) child).setDrawPosition(ListStyleButtonField.DRAWPOSITION_BOTTOM);
                }
            }
        }
    }
    
    public void setChildFontSize(int fontSize)
    {
    	Field child;
    	ListStyleButtonField link;
    	
    	for(int i=0; i<this.getFieldCount(); i++)
    	{
    		child=getField(i);
    		
    		if(child instanceof ListStyleButtonField)
    		{
    			link=(ListStyleButtonField) child;
    			link.setFontSize(fontSize);
    		}
    	}
    }
}